import turtle, datetime


# 主模块
def main():
    turtle.setup(800, 350, 200, 200)
    turtle.pensize(5)

    turtle.penup()
    turtle.fd(-300)
    turtle.pendown()

    drawDate(datetime.datetime.now().strftime("%Y-%m=%d+"))

    turtle.done()


# 根据数字画图
def drawDate(date):
    turtle.pencolor("red")
    for i in date:
        if i == "-":
            turtle.write("年", font=("Arial", 18, "normal"))
            turtle.pencolor("green")
            turtle.fd(40)
        elif i == "=":
            turtle.write("月", font=("Arial", 18, "normal"))
            turtle.pencolor("blue")
            turtle.fd(40)
        elif i == "+":
            turtle.write("日", font=("Arial", 18, "normal"))

        else:
            drawDigit(eval(i))


# 根据数字绘制七段数码管
def drawDigit(d):
    # 第一笔
    if d in [2, 3, 4, 5, 6, 8, 9]:
        drawLine(True)
    else:
        drawLine(False)
    # 第二笔
    if d in [0, 1, 3, 4, 5, 6, 8, 9]:
        drawLine(True)
    else:
        drawLine(False)
    # 第三笔
    if d in [0, 2, 3, 5, 6, 8, 9]:
        drawLine(True)
    else:
        drawLine(False)
    # 第四笔
    if d in [0, 2, 6, 8]:
        drawLine(True)
    else:
        drawLine(False)

    # 画完第四笔后直走
    turtle.left(90)

    # 第五笔
    if d in [0, 4, 5, 6, 8, 9]:
        drawLine(True)
    else:
        drawLine(False)
    # 第六笔
    if d in [0, 2, 3, 4, 5, 6, 7, 8, 9]:
        drawLine(True)
    else:
        drawLine(False)
    # 第七笔
    if d in [0, 1, 2, 3, 4, 7, 8, 9]:
        drawLine(True)
    else:
        drawLine(False)

    # 每画完第七笔后方向向左
    # 调整方向后前进
    turtle.left(180)
    turtle.penup()
    turtle.fd(20)


# 绘制单段
def drawLine(draw):
    if draw:
        turtle.pendown()
    else:
        turtle.penup()
    turtle.fd(40)
    turtle.right(90)


main()
